package com.example.bob.usinlistview;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity implements AdapterView.OnItemClickListener {

    private ListView lv;
    private ArrayAdapter<ListCellData> adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        adapter = new ArrayAdapter<ListCellData>(this,android.R.layout.simple_expandable_list_item_1);
//        adapter = new ArrayAdapter<String>(this,R.layout.list_cell);
        lv = (ListView) findViewById(R.id.ListView);
        lv.setAdapter(adapter);

//        for (int i = 0 ; i<10; i ++){
//            adapter.add(i+"item");
//        }
        adapter.add(new ListCellData("小明","男",17));
        adapter.add(new ListCellData("小红","女",52));

        lv.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        ListCellData data = adapter.getItem(i);

        Toast.makeText(this,String.format("名字:%s,性别:%s,年龄:%d",data.getUserName(),data.getSex(),data.getAge()),Toast.LENGTH_SHORT).show();
    }
}
